<template>
  <div style="min-height: 500px">
    <el-button
      type="primary"
      size="small"
      class="fr"
      @click="handleUpdateLot(1)"
      :disabled="selectedRows.length === 0"
    >审核通过</el-button>
    <el-button
      type="danger"
      size="small"
      :disabled="selectedRows.length === 0"
      class="fr mr10"
      @click="handleUpdateLot(3)"
    >审核不通过</el-button>
    <e-table :tableData="tableData" :columns="columns" :loading="loading" :pageObj="null">
      <!-- <el-table-column slot="selection" align="center" type="selection" width="55" /> -->
      <el-table-column slot="picture" label="附件图片" width="150" align="center">
        <template slot-scope="scope">
          <template v-if="scope.row.savePath && scope.row.savePath.length > 0">
            <span @click="handlePreview(scope.row)">{{ scope.row.savePath.length }}张</span>
            <!-- <img width="100%" v-viewer :src="scope.row.savePath" alt="图片" /> -->
          </template>
          <span v-else>无</span>
        </template>
      </el-table-column>
      <el-table-column label="奖惩结果" slot="reward" align="center">
        <template
          slot-scope="scope"
        >{{ scope.row.rewardType === 1 ? '奖' : '惩' }}{{ scope.row.rewardValue }}</template>
      </el-table-column>
      <el-table-column slot="action" fixed="right" width="50" align="center">
        <template slot-scope="scope">
          <el-dropdown>
            <a class="el-dropdown-link">
              <i class="el-icon-menu"></i>
            </a>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleAduit(scope.row, 1)">
                <a>审核</a>
              </el-dropdown-item>
              <el-dropdown-item @click.native="handleAduit(scope.row, 2)">
                <a class="red">审核不通过</a>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </e-table>
    <preview-modal ref="previewModal" />
  </div>
</template>

<script>
import { startEval, evalTaskEventCommit } from '@/api/eval'
import PreviewModal from '@/components/PreviewModal'
import { getSession, setSession, judgeEvalState, judgeType, formatY } from '@/utils/util'

export default {
  props: {
    list: {
      type: Object
    }
  },
  watch: {
    list: {
      handler(n, o) {
        console.log('list new', n)
      }
    }
  },
  created() {
    this.tableData = this.list.evalDetailedList
  },
  data() {
    return {
      loading: false,
      columns: [
        {
          label: '责任主体',
          prop: 'name'
        },
        // { slot: 'executorTime' },
        { slot: 'reward' },
        {
          label: '事件说明',
          prop: 'eventDescribe'
        },
        { slot: 'picture' },
        { slot: 'action' }
      ],
      tableData: [],
      row: JSON.parse(this.$route.params.row)
    }
  },
  methods: {
    handlePreview(row) {
      this.$refs.previewModal.show(row.savePath)
    },
    async handleAduit(row, num) {
      let param = { reviewState: num, evalTaskEventId: row.evalTaskEventId }
      const res = await evalTaskEventCommit([param])
      let mes = num === 1 ? '审核通过操作成功' : '审核不通过操作成功'
      if (res.state === '000000') {
        openNotification('success', mes)
      }
    },
    // 审核事件处理
    handleUpdateLot() {},
    judgeType(num) {
      return judgeType(num)
    },
    judgeState(num) {
      return judgeEvalState(num)
    },
    startEval(row, type) {
      console.log('传递row', row)

      this.$router.push({
        name: 'evaluateStartTest',
        params: { row, type }
      })
    }
  }
}
</script>
